<?php
	if ((!defined("ADMIN-AREA")) || (!in_array(SHOWVIEW,$_SESSION['access']))) {
		die("No data");
	} else {
		unset($_SESSION['access']);
	}

	include "modul/funct_stat.php";
		
	# synkronisasi antara database dengan direktori themes	
	$sqlx = "SELECT url FROM tbl_themes";
	$qryx = mysql_query($sqlx);
	$numx = mysql_num_rows($qryx);
	while($rowx = mysql_fetch_object($qryx)){
		$rowz = DIR_ABS_PATH."/".DIR_THEMES_PATH.$rowx->url;
		//echo $rowz." ".is_dir($rowz);
		if(!is_dir($rowz) || (preg_match("/svn/",$rowx->url))) {
			$sqlz = "DELETE FROM tbl_themes WHERE url='".$rowx->url."'";
			$qryz = mysql_query($sqlz);
		}
	}
	
	$dir_utama = dir("themes");
	$num = 1;
	$x = 1;
	
	$sql = "ALTER TABLE `tbl_themes` AUTO_INCREMENT =1";
	$qry = mysql_query($sql);
	
	$arr = array("..",".","common","admin-v1","admin-v2");
	$templateList = array();

	while (false !== ($isix = $dir_utama->read())) {
		$sx = DIR_ABS_PATH."/themes/".$isix;
		if ((!in_array($isix,$arr)) && (is_dir($sx))) {
			if (!preg_match("svn",$isix)) {
				$dir_asl = $isix . "/";
				$sqlx = "SELECT * FROM tbl_themes WHERE url='".$dir_asl."' LIMIT 1";
				$qryx = mysql_query($sqlx);
				$numx = mysql_num_rows($qryx);
				$rowx = mysql_fetch_object($qryx);
				$templateList[] = $isix;
				if ($numx==0) {				
					$sqlz = "INSERT INTO tbl_themes VALUES(NULL,'".$isix."','Themes ".$isix."','".$dir_asl."','no','0')";
					$qryz = mysql_query($sqlz);
				} 
			}
		}
	}
	mysql_free_result($qryx);
	
	if (in_array($_GET['template'],$templateList)) {
		include "modul/template/template_detail.php";
	} elseif (($_GET['act']!="tambah") && ($_GET['act']!="edit")) {
	echo $queryData->cari_form($THEMES_SEARCH);
	$caridata = $queryData->cari_padaku("nama_themes","keterangan");
?>
  <table border="0" align="center" cellpadding="4" cellspacing="2" class="imagesSUB">
    <tr>
      <th width="150" height="30" class="imagesSUB"><div align="center"><?php echo $THEMES_TITLE; ?></div></th>
      <th width="250" class="imagesSUB"><div align="center"><?php echo $THEMES_CONTENT; ?></div></th>
      <th width="75" nowrap="nowrap" class="imagesSUB"><div align="center"><?php echo $THEMES_SET_DEFAULT; ?></div></th>
      <th width="75" nowrap="nowrap" class="imagesSUB"><div align="center"><?php echo $THEMES_SET_ACTIVE; ?></div></th>
      <th width="75" nowrap="nowrap" class="imagesSUB"><div align="center"><?php echo $THEMES_SET_EDIT; ?></div></th>
    </tr>
    <?php
		if (isset($_SESSION['isroot'])) {
			$sqlx = "SELECT * FROM tbl_themes WHERE 1 ".$caridata;
		} else {
			$sqlx = "SELECT * FROM tbl_themes WHERE 1 ".$caridata;
		}
		$qryx = mysql_query($sqlx);
		$numx = mysql_num_rows($qryx);
		while($rowx = mysql_fetch_object($qryx)){
			$data = $x % 2;
			if ($data==0) {
				$dataX = "ganjil";
			} else {
				$dataX = "genap";
			} 
			$dir_gbr = DIR_ABS_PATH."/themes/".$rowx->url."logo.png";
			if (is_file($dir_gbr)) {
				$dir_gbr = "themes/".$rowx->url."logo.png";
			} else {
				$dir_gbr = "images/noimage.jpg";
			}
	?>
		<tr class="<?php echo $dataX; ?>" onmouseover="setBG('bg<?php echo $x; ?>','#FFFFDD')" onmouseout="setBG('bg<?php echo $x; ?>','')" id="bg<?php echo $x; ?>">
		  <th title="header=[Thumbnails] body=[<img src='<?php echo $dir_gbr; ?>' width='151' height='90'>]"><div align="left"><?php echo $rowx->nama_themes; ?></div></th>
		  <th><div align="left"><?php echo $rowx->keterangan; ?></div></th>
		  <th><div align="center">
			<?php
			if (($rowx->defaultme)=="yes") {
				echo "<a href=\"".$path."ver_template.php?show=".SHOW."&showview=".SHOWVIEW."&kode=".$rowx->idx."&stat=no&def=1\"><img src=\"images/ico_check.gif\" width=\"16\" height=\"16\" border=\"0\"></div></a></td>";
			} else {
				echo "<a href=\"".$path."ver_template.php?show=".SHOW."&showview=".SHOWVIEW."&kode=".$rowx->idx."&stat=yes&def=1\"><img src=\"images/ico_delete.gif\" width=\"16\" height=\"16\" border=\"0\"></a></div></td>";
			}
			?>
		  </div></th>
		  <th><div align="center">
			<?php
			if (($rowx->aktivasi)==1) {
				echo "<a href=\"".$path."ver_template.php?show=".SHOW."&showview=".SHOWVIEW."&kode=".$rowx->idx."&stat=no&def=2\" onclick=\"return conf1('".$THEMES_CONFIRM_DEACTIVATE."')\"><img src=\"images/ico_check.gif\" width=\"16\" height=\"16\" border=\"0\"></a></div></td>";
			} else {
				echo "<a href=\"".$path."ver_template.php?show=".SHOW."&showview=".SHOWVIEW."&kode=".$rowx->idx."&stat=yes&def=2\" onclick=\"return conf1('".$THEMES_CONFIRM_ACTIVATE."')\"><img src=\"images/ico_delete.gif\" width=\"16\" height=\"16\" border=\"0\"></a></div></td>";
			}
			?>
		  </div></th>
          <?php echo $queryData->ctrl_data('','index.php?show='.SHOW.'&showview='.SHOWVIEW.'&template='.$rowx->nama_themes,''); ?>
		</tr>
<?php
		$num++;
		$x++;
	}
?>		
</table>
<?php
	} else {
		
?>
<form action="<?php echo $path."ver_template.php?show=".SHOW."&showview=".SHOWVIEW."&kode=".$rowx->idx."&stat=no&def=1"; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="450" border="0" align="center" cellpadding="2" cellspacing="0" class="content-arial">
  <tr>
    <td width="25%" align="right" valign="middle"><div align="right"><?php echo $THEMES_TITLE; ?></div></td>
    <td width="10" align="center" valign="middle"><div align="center">:</div></td>
    <td align="left" valign="middle"><div align="left">
      <input name="nama" type="text" id="nama" class="input-title" />
    </div></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><div align="right"><?php echo $THEMES_CONTENT; ?></div></td>
    <td align="center" valign="middle"><div align="center">:</div></td>
    <td align="left"><div align="left">
      <input name="keterangan" type="text" id="keterangan" size="50" />
    </div></td>
  </tr>
  <tr>
    <td width="27%" align="right" valign="middle"><div align="right"><?php echo $THEMES_FILE; ?></div></td>
    <td align="center" valign="middle"><div align="center">:</div></td>
    <td width="65%" align="left">
      <div align="left">
        <input name="namafile" type="file" id="namafile" />
      </div>    </td>
  </tr>
  <tr>
    <td align="right" valign="middle"><div align="right"></div></td>
    <td align="center" valign="middle"><div align="center"></div></td>
    <td align="left"><div align="left">
        <input type="submit" name="submit" id="submit" value="<?php echo $DEV_CTRL_SUBMIT; ?>" />
          <input type="reset" name="Reset" value="<?php echo $DEV_CTRL_RESET; ?>" />
    </div></td>
  </tr>
</table>
</form>
<?php
	}
?>
